package gov.child.util;

import java.util.Random;

/**
 * @author fzh
 * @since 2017/9/12
 */
public class StringUtil {

    private static Random random = new Random();

    public static void assertStringLength(String src) {
        if (src.isEmpty()) throw new RuntimeException("String's length is asserted not equal 0.");
    }

    public static String randomString() {
        return randomString(6);
    }

    public static String randomString(int length) {
        StringBuilder builder = new StringBuilder();
        int t;
        for (int j = 0; j < length; j++) {
            t = random.nextInt(26);
            int x = t % 3;
            if (x == 0) {
                builder.append((char) (97 + t));
            } else if (x == 1) {
                builder.append((char) (65 + t));
            } else {
                builder.append((char) (48 + random.nextInt(9)));
            }
        }
        return builder.toString();
    }
}
